package net.minecraft.src;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;

public class ReadIdFile 
{
	
	public static Map< Class, String > keys = new HashMap< Class,String >(){
		{
			put( BlockPixel.class,"Pixel" );
			put( BlockConductiveLamp.class,"Conductive_Lamp" );
			put( BlockReceiver.class,"Receiver" );
			put( BlockTransmiter.class,"Transmiter" );
			put( BlockSequencer.class,"Sequencer" );
			put( BlockFlipFlop.class,"FlipFlop" );
			put( BlockSticky.class,"Sticky" );
		}
	};

	public static int getIdFromFile( Class idToGetClass )
	{
		    String  compare = keys.get(idToGetClass );
		    
		    assert( compare != null );
		    
		    int  id = getIdFromFile( "/mod/idConfig.txt", compare );
			if( id != -1 )
			{
				assert( id < 256 );
				return  id;				
			}
			
			return -1;
	}




	public static  int 
	getIdFromFile( String  fileName, String key )
	{
	  try{
	  
	  BufferedReader br = new BufferedReader(new InputStreamReader(ReadIdFile.class.getResourceAsStream(fileName)));
	  String strLine;
	  
	  while ((strLine = br.readLine()) != null)   {
	     
		   boolean  match = strLine.regionMatches(
		   0/* start  point */,
		   key /* key */,
		   /* key offset */0,
		   key.length());
		   
		   if( match )
		   {
				String  string = strLine.substring(key.length()); 
		   
				return Integer.parseInt( string.trim()  );

		   }		
	  }


	  return -1;
	  
	    }catch (Exception e){//Catch exception if any
	  System.err.println("Error: " + e.getMessage());
	  
	  }
	  
	  return -1;
	}
    protected ReadIdFile(String fileName)
    {

    }
    
}
